/**
 * 商店设置模块
 */
(function(window) {
    'use strict';
    
    // 全局变量用于存储商店名称
    let storeNames = {
        zh: "商店名称",
        uy: "دۇكان ئىسىمى"
    };
    
    /**
     * 获取商店设置
     */
    function getStoreSettings() {
        return $.ajax({
            url: '/api/store/settings',
            type: 'GET',
            dataType: 'json'
        });
    }
    
    /**
     * 保存商店设置
     */
    function saveStoreSettings(settings) {
        return $.ajax({
            url: '/api/store/settings',
            type: 'POST',
            contentType: 'application/json',
            data: JSON.stringify(settings)
        });
    }
    
    /**
     * 上传Logo
     */
    function uploadLogo(file) {
        const formData = new FormData();
        formData.append('logo', file);
        
        return $.ajax({
            url: '/api/upload/logo',
            type: 'POST',
            data: formData,
            processData: false,
            contentType: false,
            headers: {
                'X-Requested-With': 'XMLHttpRequest'
            }
        });
    }
    
    /**
     * 更新商店名称显示
     */
    function updateStoreName(zhName, uyName) {
        if (zhName !== undefined) storeNames.zh = zhName;
        if (uyName !== undefined) storeNames.uy = uyName;
        
        const currentLang = window.currentLang || 'zh';
        const storeName = currentLang === 'zh' ? storeNames.zh : storeNames.uy;
        $('.store-name').text(storeName);
    }
    
    // 暴露API
    window.StoreModule = {
        getStoreSettings: getStoreSettings,
        saveStoreSettings: saveStoreSettings,
        uploadLogo: uploadLogo,
        updateStoreName: updateStoreName,
        getStoreNames: () => storeNames
    };
    
    // 兼容旧代码
    window.storeNames = storeNames;
    window.updateStoreName = updateStoreName;
    
})(window);

